package com.scenic.map.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

@Api(tags = "地图服务")
@RestController
@RequestMapping("/api/map")
public class MapController {

    private static final String AMAP_KEY = "770e1be9dd8196f7877303dd3a0d49a5";

    @ApiOperation(value = "获取路线")
    @ApiImplicitParams( {
            @ApiImplicitParam(name = "origin", value = "起点", required = true, dataType = "String"),
            @ApiImplicitParam(name = "destination", value = "终点", required = true, dataType = "String")
    })
    @GetMapping("/route")
    public String getRoute(@RequestParam String origin, @RequestParam String destination) {
        // origin, destination 格式: "经度,纬度"
        String url = "https://restapi.amap.com/v3/direction/walking"
                + "?origin=" + origin
                + "&destination=" + destination
                + "&key=" + AMAP_KEY;
        try {
            RestTemplate restTemplate = new RestTemplate();
            return restTemplate.getForObject(url, String.class);
        } catch (Exception e) {
            e.printStackTrace();
            return "{\"status\":\"0\",\"info\":\"后端请求高德API失败\"}";
        }
    }
} 